package com.gt.wc

import com.gt.SCUtil
import org.apache.log4j.Logger
import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object WorldCount_02 {
  private val logger: Logger = Logger.getLogger("WorldCount_02")

  def main(args: Array[String]): Unit = {
    val sc = SCUtil.createLocalSc()
    val rdd1: RDD[String] = sc.textFile("./data")
    val rdd2: RDD[(String, Int)] = rdd1.flatMap(a => a.split(" ")).map(a => (a, 1))
    val rdd3: RDD[(String, Int)] = rdd2.reduceByKey((x, y) => x + y)
    rdd3.foreach(println)

    rdd3.collect().foreach(x => logger.error(x))

    sc.stop()
  }

}
